#ifndef CHANNEL_H
#define CHANNEL_H

#include "common.h"
#include "event_loop.h"
#include "buffer.h"

#define EVENT_TIMEOUT 0x01
/** Wait for a socket or FD to become readable */
#define EVENT_READ 0x02
/** Wait for a socket or FD to become writeable */
#define EVENT_WRITE 0x04
/** Wait for a POSIX signal to be raised*/
#define EVENT_SIGNAL 0x08

typedef int (*event_read_callback)(void *data); // 事件读回调

typedef int (*event_write_callback)(void *data); // 事件写回调

// channel 客户端连接（FD）与服务器的通道
struct channel
{
    int fd;
    int events; //表示event类型

    event_read_callback eventReadCallback;
    event_write_callback eventWriteCallback;
    void *data; //回调数据，callback data, 可能是 event_loop，也可能是 tcp_server 或者 tcp_connection
};

// 新建 channel
struct channel *
channel_new(int fd, int events, event_read_callback eventReadCallback, event_write_callback eventWriteCallback,
            void *data);

// channel 是否可写
int channel_write_event_is_enabled(struct channel *channel);

// 开启 channel 写事件
int channel_write_event_enable(struct channel *channel);

// 关闭 channel 写事件
int channel_write_event_disable(struct channel *channel);

#endif